


import 'package:flutter/material.dart';
import 'package:flutter_lib/utils/LogUtils.dart';
import 'package:flutter_lib/utils/ToastUtils.dart';
import 'package:flutter_my_web/constants/Global.dart';
import 'package:flutter_my_web/event/change_root_event.dart';
import 'package:flutter_my_web/utils/Utils.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';
import 'package:get/get.dart';


showLoginDialog(BuildContext context){
  showDialog(context: context, builder: (builder){
    return Dialog(child: LoginDialog(),);
  });
}

class LoginDialog extends StatefulWidget {
  const LoginDialog({Key? key}) : super(key: key);

  @override
  _LoginDialogState createState() => _LoginDialogState();
}

class _LoginDialogState extends State<LoginDialog> {
  String TextFieldStr = "";
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 350,
      padding: EdgeInsets.all(40),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20.0),
        color: const Color(0xfff6f5fc),
        boxShadow: [
          BoxShadow(
            color: const Color(0x3319195d),
            offset: Offset(0, 10),
            blurRadius: 45,
          ),
        ],
      ),
      child: Material(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
          SimpleText(
            'Login',fontSize: 32,
            color: const Color(0xff10103e),
            fontWeight: FontWeight.w700,
          ),
            TextField(
              onChanged: (s){
                TextFieldStr = s;
              },
              maxLength: 10,
              decoration: InputDecoration(
                border: OutlineInputBorder(),
                hintText: '请输入管理员密码',
                labelText: '密码',
                prefixIcon: Icon(Icons.person),
                labelStyle: TextStyle(
                  fontSize: 14,
                ),
              ),
            ),
            InkWell(
              onTap: (){
                LogUtils.e("TextFieldStr:${TextFieldStr}");
                if (TextFieldStr == "570571"){
                  Global.isRoot = true;
                  showSnackBar("管理员设置成功");
                  changeRootEventBus.fire(ChangeRootEvent());
                }else{
                  showSnackBar("密码错误");
                }
                 Navigator.of(context).pop();
              },
              child: Container(
                margin: EdgeInsets.all(10),
                height: 70,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5.0),
                  gradient: LinearGradient(
                    begin: Alignment(-1.0, -1.0),
                    end: Alignment(1.0, 1.0),
                    colors: [const Color(0xff24246f), const Color(0xff141455)],
                    stops: [0.0, 1.0],
                  ),
                  boxShadow: [
                    BoxShadow(
                      color: const Color(0x5a21216b),
                      offset: Offset(0, 5),
                      blurRadius: 10,
                    ),
                  ],
                ),
                child: Center(child: SimpleText("确定",color: Colors.white,fontSize: 20,),),
              ),
            )
        ],),
      ),
    );
  }
}
